import { Form, Input, Radio, message } from 'antd';
import React, { useEffect, useState } from 'react';
import CommonModal from 'components/common/CommonModal';
import { editPassword, editUserInfo } from 'apis/userCenter';

export default function (props): JSX.Element {
    const onSubmit = (data, loadinCallback?: () => void, closeModalCallback?: () => void) => {
        console.log(data);
        editUserInfo(data)
            .then((res) => {
                message.success('修改成功');
                refresh();
                loadinCallback?.();
                closeModalCallback?.();
            })
            .finally(() => {
                loadinCallback?.();
            });
    };
    const { infoData, refresh } = props;

    // 新增弹框
    const { visible, setVisible } = props;
    return (
        <CommonModal
            title='修改信息'
            width={600}
            styles={{ body: { marginTop: '20px', marginBottom: '20px' } }}
            open={visible}
            close={() => {
                setVisible(false);
            }}
            formSetting={{ labelCol: { span: 4 }, wrapperCol: { span: 20 } }}
            onSubmit={onSubmit}
            initFormData={infoData}
        >
            <Form.Item name='name' label='姓名' rules={[{ required: true, message: '请输入姓名' }]}>
                <Input placeholder='请输入姓名' maxLength={16} />
            </Form.Item>
            <Form.Item name='sex' label='性别' rules={[{ required: true, message: '请选择性别' }]}>
                <Radio.Group
                    options={[
                        { label: '男', value: 1 },
                        { label: '女', value: 2 },
                    ]}
                />
            </Form.Item>
        </CommonModal>
    );
}
